package com.thientan.model

import com.thientan.model.core.AuditingInfo
import com.thientan.model.enums.LoaiChiTietThuChi
import com.thientan.utils.Constants

/**
 * Domain class used to represent entity from table CHI_TIET_THU_CHI
 * @author DINH HONG CHAU
 *
 */
class ChiTietThuChi {
	static constraints = {
		auditingInfo(nullable : true)
		nhanVien(nullable : true)
		ghiChu(nullable : true, maxSize : 1000)
	}

	static embedded = ['auditingInfo']
	AuditingInfo auditingInfo

	static mapping = {
		table 'CHI_TIET_THU_CHI'
		id generator : 'increment'
		columns {
			id column : 'CHI_TIET_ID'
			hopDong column: 'HOP_DONG_ID'
			nhanVien column: 'NHAN_VIEN_ID'
			quyetToan column: 'QUYET_TOAN', class: Boolean
		}
	}

	static belongsTo = [hopDong : HopDong]

	HopDong hopDong
	NhanVien nhanVien
	LoaiChiTietThuChi loaiChiTiet = LoaiChiTietThuChi.TRA_GOP
	Double soTien
	Date ngayLap
	boolean quyetToan = false
	String ghiChu
	
	static transients = ['tenThuNgan', 'tenNvNhap', 'ngayTao', 'ngayLapText','loaiChiTietText']
	
	String tenThuNgan
	String tenNvNhap
	Date ngayTao
	String getNgayLapText() {
		new java.text.SimpleDateFormat(Constants.DEFAULT_DATE_FORMAT).format(ngayLap)
	}
	
	String getLoaiChiTietText() {
		if(loaiChiTiet){
			return loaiChiTiet.name()
		}
		return ""
	}
}
